<template>
  <n-card :bordered="false" class="proCard">
    <BasicForm @register="register" @submit="handleSubmit" @reset="handleReset">
      <template #statusSlot="{ model, field }">
        <n-input v-model:value="model[field]" />
      </template>
    </BasicForm>

    <div class="flex flex-wrap" >
      <div class="w-[100px] flex flex-col mr-[20px] mb-[20px] " v-for="item in 10" :key="item">
        <n-image
    width="100"
    src="https://07akioni.oss-cn-beijing.aliyuncs.com/07akioni.jpeg"
  />
        <n-button class="mt-[15px]" @click="download('https://07akioni.oss-cn-beijing.aliyuncs.com/07akioni.jpeg')">下载</n-button>
      </div>
    </div>
  </n-card>
</template>

<script lang="ts" setup>
  import { h, reactive, ref } from 'vue';
  import { BasicTable, TableAction } from '@/components/Table';
  import { BasicForm, FormSchema, useForm } from '@/components/Form/index';
  import { getEmailTableList } from '@/api/table/list';
  import { PlusOutlined } from '@vicons/antd';
  import { useRouter } from 'vue-router';
  import { type FormRules } from 'naive-ui';
  import {downloadByUrl} from '@/utils/downloadFile'
  const schemas: FormSchema[] = [
    {
      field: 'target_url',
      component: 'NInput',
      label: '商品链接',
      componentProps: {
        placeholder: '请输入商品链接',
        onInput: (e: any) => {
          console.log(e);
        },
      },
      rules: [{ required: true, message: '请输入商品链接', trigger: ['blur'] }],
    },
  ];

  const router = useRouter();
  const formRef: any = ref(null);
  const actionRef = ref();

  const showModal = ref(false);
  const formBtnLoading = ref(false);

  const [register, { getFieldsValue }] = useForm({
    gridProps: { cols: '1 s:1 m:2 l:3 xl:4 2xl:4' },
    labelWidth: 80,
    schemas,
  });

  function download(url) {
    downloadByUrl({
      url
    })
  }

  function addTable() {
    showModal.value = true;
  }

  const loadDataTable = async () => {
        return await getEmailTableList({ ...getFieldsValue() });
  };

  function onCheckedRow(rowKeys) {
    console.log(rowKeys);
  }

  function reloadTable() {
    actionRef.value.reload();
  }

  async function handleSubmit(values: Recordable) {
    await loadDataTable();
  }

  function handleReset(values: Recordable) {
    console.log(values);
  }
</script>

<style lang="less" scoped></style>
